package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.Mail;
import com.ruoyi.manage.service.IMailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邮件管理Controller
 * 
 * @author Admin
 * @date 2025-09-06
 */
@RestController
@RequestMapping("/manage/mail")
public class MailController extends BaseController
{
    @Autowired
    private IMailService mailService;

    /**
     * 查询邮件管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:list')")
    @GetMapping("/list")
    public TableDataInfo list(Mail mail)
    {
        startPage();
        List<Mail> list = mailService.selectMailList(mail);
        return getDataTable(list);
    }

    /**
     * 导出邮件管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:export')")
    @Log(title = "邮件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mail mail)
    {
        List<Mail> list = mailService.selectMailList(mail);
        ExcelUtil<Mail> util = new ExcelUtil<Mail>(Mail.class);
        util.exportExcel(response, list, "邮件管理数据");
    }

    /**
     * 获取邮件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mailService.selectMailById(id));
    }

    /**
     * 新增邮件管理
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:add')")
    @Log(title = "邮件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Mail mail)
    {
        return toAjax(mailService.insertMail(mail));
    }

    /**
     * 修改邮件管理
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:edit')")
    @Log(title = "邮件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Mail mail)
    {
        return toAjax(mailService.updateMail(mail));
    }

    /**
     * 删除邮件管理
     */
    @PreAuthorize("@ss.hasPermi('manage:mail:remove')")
    @Log(title = "邮件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mailService.deleteMailByIds(ids));
    }
}
